package com.ruoyi.net.netconf.examples;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.net.netconf.Device;
import com.ruoyi.net.netconf.NetconfException;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class CreateDevice {

    private static final String HOSTNAME = "10.1.1.1";
    private static final String USERNAME = "router";
    private static final String PASSWORD = "fos";
    private static final String PEM_KEY_FILE_PATH = "/tmp/pemFile";

    private Map<String, Device> devices = new HashMap<>();

    public static Device createDevice(String hostname, String userName, String password) throws NetconfException {
        return Device.builder()
                .hostName(hostname)
                .userName(StringUtils.isEmpty(userName) ? USERNAME : userName)
                .password(StringUtils.isEmpty(password) ? PASSWORD : password)
                .strictHostKeyChecking(false)
                .build();
    }
    /**
     * Create a new Device using username and password authentication.
     *
     * @return an unconnected Device object.
     * @throws NetconfException if there are issues creating the Device.
     */
    public static Device createDevice() throws NetconfException {
        return Device.builder()
                .hostName(HOSTNAME)
                .userName(USERNAME)
                .password(PASSWORD)
                .strictHostKeyChecking(false)
                .build();
    }

    /**
     * Create a new Device using username and public key file.
     *
     * @param keyFile the path to a private key file used to authenticate to the Device.
     * @return an unconnected Device object.
     * @throws NetconfException if there are issues creating the Device.
     */
    public static Device createDeviceWithKeyAuth(String keyFile) throws NetconfException {
        return Device.builder()
                .hostName(HOSTNAME)
                .userName(USERNAME)
                .pemKeyFile(PEM_KEY_FILE_PATH)
                .strictHostKeyChecking(false)
                .build();
    }
}
